/*
 *   Copyright [2008] [Anay Nayak]
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.googlecode.equalsnhashcode.inspections;

import com.googlecode.equalsnhashcode.finders.HashcodeMethodFinder;
import com.googlecode.equalsnhashcode.finders.ProblemFinder;
import com.intellij.codeInsight.daemon.GroupNames;
import com.intellij.codeInspection.BaseJavaLocalInspectionTool;
import com.intellij.codeInspection.InspectionManager;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class HashCodeInspection extends BaseJavaLocalInspectionTool {
    private static final String FIELD_NOT_INCLUDED_IN_HASHCODE_METHOD = "field '%s' not included in hashCode method";

    @Nullable
    public ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager inspectionManager, boolean onTheFly) {
        PsiMethod psiMethod = new HashcodeMethodFinder(psiClass).find();
        List<ProblemDescriptor> hashcodeProblemDescriptors = new ProblemFinder(psiClass, inspectionManager, FIELD_NOT_INCLUDED_IN_HASHCODE_METHOD).process(psiMethod);
        return hashcodeProblemDescriptors.toArray(new ProblemDescriptor[hashcodeProblemDescriptors.size()]);
    }

    public boolean runForWholeFile() {
        return true;
    }

    @Nls
    @NotNull
    public String getGroupDisplayName() {
        return GroupNames.BUGS_GROUP_NAME;
    }

    @Nls
    @NotNull
    public String getDisplayName() {
        return "field not used in hashCode()";
    }

    @NonNls
    @NotNull
    public String getShortName() {
        return "HashCodeInspection";
    }

    public boolean isEnabledByDefault() {
        return true;
    }
}


